<script setup>
import {getCurrentInstance, ref} from "vue";
import {ElMessage} from "element-plus";

const customer_name = ref("")
const customer_phone = ref("")
const customer_address = ref("")
const visible = ref(false);
const {proxy} = getCurrentInstance();
const emits = defineEmits(['close'])

const close = () => {
  visible.value = false
  emits('close', false);
}

const open = () => {
  visible.value = true
}


defineExpose({
  open
})

const submitCustomer = (uploadFile) => {
  proxy.$axios.post("http://localhost:8091/TbCustomer/addCustomer",
      {
        custName: customer_name.value,
        custMobile: customer_phone.value,
        custAddress: customer_address.value,
        custTicket: 0
      }
  ).then(resp => {
    if (resp.data > 0) {
      ElMessage.success("操作成功");
    } else {
      ElMessage.error("操作失败");
    }
    visible.value = false;
    customer_name.value = "";
    customer_phone.value = "";
    customer_address.value = "";
  })
}
</script>

<template>
  <el-dialog v-model="visible" @close="close" width="20%">
    <div id="formStyle">
      <el-form>
        <el-form-item><span>姓名</span>
          <el-input v-model="customer_name"></el-input>
        </el-form-item>
        <el-form-item><span>电话</span>
          <el-input v-model="customer_phone"></el-input>
        </el-form-item>
        <el-form-item><span>地址</span>
          <el-input v-model="customer_address"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitCustomer">提交</el-button>
        </el-form-item>
      </el-form>
    </div>
  </el-dialog>
</template>

<style scoped lang="scss">
.el-dialog {
  .el-input {
    margin-left: 20px;
    width: 70%;
  }

  #formStyle {
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .avatar-uploader .el-upload {
    border: 1px dashed var(--el-border-color);
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: var(--el-transition-duration-fast);
  }

  .avatar-uploader .el-upload:hover {
    border-color: var(--el-color-primary);
  }

  :deep(.el-icon .avatar-uploader-icon) {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    text-align: center;
  }
}

</style>